package com.daocao.ds.adapter;

import android.content.Context;
import android.graphics.Typeface;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.daocao.ds.R;
import com.daocao.ds.api.model.ManagerListModel;
import com.daocao.ds.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class ManagerReportAdapter extends ItemAdapter<ManagerListModel.DatasBean, ManagerReportAdapter.DefaultHolder> {


    private final int x24;
    private final int colorOne;
    private final int colorTwo;
    private Context context;

    public ManagerReportAdapter(Context context) {
        super(context);
        this.context = context;
        x24 = context.getResources().getDimensionPixelSize(R.dimen.x24);
        colorOne = 0xff999999;
        colorTwo = 0xff333333;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_manager_report, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        ManagerListModel.DatasBean item = getItem(position);

        holder.txtInfoOne.setText(getSpanTextOne(item.real_name, item.borrow_amount, item.start_date));

        holder.txtInfoTwo.setText(getSpanTextTwo(item.limit_days, item.repay_interest, item.repay_date));
    }

    private Spanned getSpanTextOne(String one, String two, String three) {
        if (TextUtils.isEmpty(one)) {
            one = "";
        }
        if (TextUtils.isEmpty(two)) {
            two = "0";
        }
        if (TextUtils.isEmpty(three)) {
            three = "";
        }
        return Spans.with(context).font("借款人：", x24, colorOne).font(one, x24, colorTwo).
                font("\n借款金额：", x24, colorOne).font(two + "元", x24, colorTwo).
                font("\n出借日期：", x24, colorOne).font(three, x24, colorTwo).
                build();
    }

    private Spanned getSpanTextTwo(String one, String two, String three) {
        if (TextUtils.isEmpty(one)) {
            one = "";
        }
        if (TextUtils.isEmpty(two)) {
            two = "0";
        }
        if (TextUtils.isEmpty(three)) {
            three = "";
        }
        return Spans.with(context).font("借款期限：", x24, colorOne).font(one + "天", x24, colorTwo).
                font("\n收益金额：", x24, colorOne).font(two + "元", x24, colorTwo).
                font("\n实际回款日期：", x24, colorOne).font(three, x24, colorTwo).
                build();
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_info_one)
        TextView txtInfoOne;
        @BindView(R.id.txt_info_two)
        TextView txtInfoTwo;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onSuccess();
    }
}
